package cn.edu.buaa.cnsatm.traffic_big_data_server.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
 * @author:  LX
 * @description: 将项目外的目录映射到URL
 * @date:2019/10/11
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //addResourceHandler是指你想在url请求的路径
        //addResourceLocations是图片存放的真实路径
        PropertiesUtil.setProperties();//不在这里启用配置就无法成功运行项目

        registry.addResourceHandler(PropertiesUtil.properties.getProperty("CLOUD_IMAGE_MAPPING_DIRECTORY")).
                addResourceLocations("file:" + PropertiesUtil.properties.getProperty("CLOUD_IMAGE_DIRECTORY"));//卫星云图
        /*实际地址结尾必须加斜杠*/
        WebMvcConfigurer.super.addResourceHandlers(registry);

        registry.addResourceHandler(PropertiesUtil.properties.getProperty("ROAD_IMAGE_MAPPING_DIRECTORY")).
                addResourceLocations("file:" + PropertiesUtil.properties.getProperty("ROAD_IMAGE_DIRECTORY"));//公路图
        /*实际地址结尾必须加斜杠*/
        WebMvcConfigurer.super.addResourceHandlers(registry);

        registry.addResourceHandler(PropertiesUtil.properties.getProperty("VEHICLE_IMAGE_MAPPING_DIRECTORY")).
                addResourceLocations("file:" + PropertiesUtil.properties.getProperty("VEHICLE_IMAGE_DIRECTORY"));//载具图
        /*实际地址结尾必须加斜杠*/

        registry.addResourceHandler(PropertiesUtil.properties.getProperty("BZDW_CONFIG_MAPPING_DIRECTORY")).
                addResourceLocations("file:" + PropertiesUtil.properties.getProperty("BZDW_CONFIG"));//载具图
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
    public static void main(String args[]){
        System.out.println(PropertiesUtil.properties.getProperty("server.port"));
    }
}

